import api from "../../api/index.js";

//当前home模块中的state数据仓库
const state={
    loopImg:[],
    classifyImg:[],
    lowerMoneyMoudle:[],
    hotClassifyMoudle:[],
    thinkYourLikeMoudle:[]
};

//当前home模块中的mutation事件仓库
const mutations={
    setLoopImg(state,nv){
        state.loopImg=nv;
    },
    setClassifyImg(state,nv){
        state.classifyImg=nv;
    },
    setLowerMoneyMoudle(state,nv){
        state.lowerMoneyMoudle=nv;
    },
    setHotClassifyMoudle(state,nv){
        state.hotClassifyMoudle=nv;
    },
    setThinkYourLikeMoudle(state,nv){
        state.thinkYourLikeMoudle=nv;
    }
};

//当前home模块中的ajax集中事件仓库
const actions={
    loadImage(store){
        api.loadImgForHome({
            appPlat:"m",
            pids:"136556,106930,51833,51836"
        }).then((data)=>{
            if(!data.success){
                return Promise.reject(data.returnMessage);
            };
            store.commit("setClassifyImg",data.data[106930].list);
            store.commit("setLowerMoneyMoudle",data.data[51833].list);
            store.commit("setHotClassifyMoudle",data.data[51836].list);
        }).catch(api.showError);
    },
    loadYourLike(store){
        api.loadThinkYourLike({
            pid:"9750",
            sort:"pop",
            cKey:46
        }).then((data)=>{
            // console.log(data);
            if(!data.success){
                return Promise.reject("请求失败");
            };
            store.commit("setThinkYourLikeMoudle",data.result.wall.docs);
        }).catch(api.showError);
    }
};

export default {
    state,
    mutations,
    actions
}